package com.fyzk.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.fyzk.activity.prize.BeiDanPrizeActivity;
import com.fyzk.activity.prize.InquiryInfo;
import com.fyzk.activity.prize.JLPrizeActivity;
import com.fyzk.activity.prize.JZPrizeActivity;
import com.fyzk.activity.prize.NumberLotteryPrizeHistroyActivity;
import com.fyzk.activity.prize.PrizeSelectItemView;
import com.fyzk.utils.IntentParamUtils;
import com.fyzk.utils.LogUtil;
import com.fyzk.utils.LotteryIDUtils;
import com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder;
import com.marshalchen.ultimaterecyclerview.UltimateViewAdapter;

import java.util.List;

public class PrizeLotteryAdapter extends UltimateViewAdapter {
    private List<InquiryInfo> mArrInquiryInfos;
    private Context mContext;

    public PrizeLotteryAdapter(Context context, List<InquiryInfo> inquiryInfos) {
        this.mArrInquiryInfos = inquiryInfos;
        this.mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder newFooterHolder(View view) {
        return null;
    }

    @Override
    public RecyclerView.ViewHolder newHeaderHolder(View view) {
        return null;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
        PrizeSelectItemView prizeItemView = new PrizeSelectItemView(mContext);
        ViewHolder holder = new ViewHolder(prizeItemView);
        return holder;
    }

    class ViewHolder extends UltimateRecyclerviewViewHolder {

        public ViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void onItemSelected() {
            itemView.setBackgroundColor(Color.LTGRAY);
        }

        @Override
        public void onItemClear() {
            itemView.setBackgroundColor(0);
        }
    }


    @Override
    public int getAdapterItemCount() {
        return mArrInquiryInfos.size();
    }

    @Override
    public long generateHeaderId(int position) {
        return -1;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (position < getItemCount() && position < mArrInquiryInfos.size()) {
            ((PrizeSelectItemView) ((RecyclerView.ViewHolder) holder).itemView)
                    .setPrizeItemData(mArrInquiryInfos.get(customHeaderView != null ?
                            position - 1 : position));


            ((RecyclerView.ViewHolder) holder).itemView.setOnClickListener(new View
                    .OnClickListener() {


                @Override
                public void onClick(View v) {
                    int selectLotteryId = mArrInquiryInfos.get(position).lotteryType;
//
                    Intent intent = new Intent();
                    switch (selectLotteryId) {
                        case LotteryIDUtils.JLSF_LOTTERY_ID_INT:
                            intent.setClass(mContext, JLPrizeActivity.class);
                            break;
                        case LotteryIDUtils.JZRFSPF_LOTTERY_ID_INT:
                            intent.setClass(mContext, JZPrizeActivity.class);
                            break;
                        case LotteryIDUtils.DCSPF_LOTTERY_ID_INT:
                            intent.setClass(mContext, BeiDanPrizeActivity.class);
                            intent.putExtra("phase",mArrInquiryInfos.get(position).phase);
                            break;
                        case LotteryIDUtils.ZCSFC_LOTTERY_ID_INT:
                        case LotteryIDUtils.ZCRXJ_LOTTERY_ID_INT:
                        case LotteryIDUtils.ZCBQC_LOTTERY_ID_INT:
                        case LotteryIDUtils.ZCJQC_LOTTERY_ID_INT:
                            intent.setClass(mContext, NumberLotteryPrizeHistroyActivity.class);
                            break;
                        case LotteryIDUtils.SSQ_LOTTERY_ID_INT:
                        case LotteryIDUtils.QXC_LOTTERY_ID_INT:
                        case LotteryIDUtils.FC3D_LOTTERY_ID_INT:
                        case LotteryIDUtils.PL3_LOTTERY_ID_INT:
                        case LotteryIDUtils.PL5_LOTTERY_ID_INT:
                        case LotteryIDUtils.DLT_LOTTERY_ID_INT:
                        case LotteryIDUtils.QLC_LOTTERY_ID_INT:
                        case LotteryIDUtils.CQSSC_LOTTERY_ID_INT:
                        case LotteryIDUtils.SD11XUAN5_LOTTERY_ID_INT:
                        case LotteryIDUtils.GD11XUAN5_LOTTERY_ID_INT:
                        case LotteryIDUtils.XJ11XUAN5_LOTTERY_ID_INT:
                        case LotteryIDUtils.ANHUIK3_LOTTERY_ID_INT:
                        case LotteryIDUtils.NXK3_LOTTERY_ID_INT:
                        case LotteryIDUtils.JSK3_LOTTERY_ID_INT:
                        case LotteryIDUtils.JLK3_LOTTERY_ID_INT:
                        case LotteryIDUtils.GXK3_LOTTERY_ID_INT:
                        case LotteryIDUtils.KLSF_LOTTERY_ID_INT:
                        case LotteryIDUtils.GDKLSF_LOTTERY_ID_INT:
                        case LotteryIDUtils.KLPK_LOTTERY_ID_INT:
                            intent.setClass(mContext, NumberLotteryPrizeHistroyActivity.class);
                            break;
                    }
                    intent.putExtra(IntentParamUtils.LOTTERYID, selectLotteryId);
                    try {
                        mContext.startActivity(intent);
                    } catch (Exception e) {
                        LogUtil.v(e.getMessage());
                    }
                }
            });
        }
    }


    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        return null;
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {
    }

}
